package com.zgc.web.intercepter;



import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;
import com.zgc.domain.User;
import com.zgc.utils.ZGCContext;

public class ZgcLoginIntercepter extends MethodFilterInterceptor {

	@Override
	protected String doIntercept(ActionInvocation invocation) throws Exception {
		System.out.println("自定义拦截器执行了...");
		//获得session中的loginuser
		User loginUser =ZGCContext.getLoginUser();
		//如果是空 拦截
		if (loginUser == null) {
			ActionSupport action = (ActionSupport)invocation.getAction();
			action.addActionError("需要先登录");
			return "login";
		}else {
			//已经登录 放行
			return invocation.invoke();
		}
	}

}
